package com.raysdata.smartcity.dao.sys;

import com.raysdata.smartcity.dao.RzBaseDao;
import com.raysdata.smartcity.dto.Menu;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by yl on 2016/10/17.
 */
@Component
public class MenuDao {
    Log log = LogFactory.getLog(MenuDao.class);
    @Autowired
    private RzBaseDao rzBaseDao;

    public List<Menu> queryMenus(String userId) {
        StringBuilder sb = new StringBuilder();
        sb.append(" SELECT m.* FROM ss_menu m ");
        sb.append(" LEFT JOIN ss_role_menu rm ON m.menu_id = rm.menu_id ");
        sb.append(" LEFT JOIN ss_user_role ur ON rm.role_id = ur.role_id ");
        sb.append(" WHERE m.status=0 AND ur.user_id = ? group BY m.menu_id ");
        sb.append(" ORDER BY m.sort_no ");
        Object[] params = new Object[1];
        params[0] = userId;
        return rzBaseDao.query(sb.toString(), Menu.class, params);
    }

    public List<Menu> queryAllMenus(){
        String sql="select menu_id,name from ss_menu where status=0 ";
        return rzBaseDao.query(sql,Menu.class);
    }
}
